<template>
    <div class="ratings" ref="ratings">
        <div class="ratings-content">
            <div class="overview">
                <div class="overview-left">
                    <h1 class="score">{{seller.score}}</h1>
                    <div class="title">综合评分</div>
                    <div class="rank">高于周边商家{{seller.rankRate}}%</div>
                </div>
                <div class="overview-right">
                    <div class="score-wrapper">
                        <span class="title">服务态度</span>
                        <star class="star" :size="36" :score="seller.serviceScore"></star>
                        <span class="score">{{seller.serviceScore}}</span>
                    </div>
                    <div class="score-wrapper">
                        <span class="title">商品评分</span>
                        <star class="star" :size="36" :score="seller.foodScore"></star>
                        <span class="score">{{seller.foodScore}}</span>
                    </div>
                    <div class="time">
                        <span class="title">送达时间</span>
                        <span class="deltime">{{seller.deliveryTime}}分钟</span>
                    </div>

                </div>
            </div>
            <split></split>
            <ratingselect :ratings="ratings"
            :selectType="selectType" 
            :onlyContent="onlyContent" :desc="desc" 
            ></ratingselect>
            <div class="rating-wrapper">
                <ul>
                    <li v-for="(rating,key) in ratings" :key="key" class="item"
                    v-show="needShow(rating.rateType,rating.text)">
                        <div class="avatar">
                            <img :src="rating.avatar" alt="" width="28">
                        </div>
                        <div class="content">
                            <h1 class="name">{{rating.username}}</h1>
                            <div class="star-wrapper">
                                <star class="star" :size="24" :score="rating.score"></star>
                                <span class="delivery" v-show="rating.deliveryTime">{{rating.deliveryTime}}分钟送达</span>
                            </div>
                            <p class="text">{{rating.text}}</p>
                            <div class="recommend" v-show="rating.recommend && rating.recommend.length>0">
                                <span class="icon-thumb_up" ></span>
                                <span class="recommend-item" v-for="(item,key) in rating.recommend" :key="key">
                                    {{item}}
                                </span>
                            </div>
                            <div class="time">{{rating.rateTime | formatDate}}</div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>
<script>
import BScroll from 'better-scroll'
import moment from 'moment'
import split from '../split/split'
import star from '../star/star'
import ratingselect from '../ratingselect/ratingselect'
const POSITIVE = 0
const NEGATIVE = 1
const ALL = 2
export default {
    components :{
        split,star,ratingselect
    },
    props:['seller'],
    data() {
        return {
            showFlag: false,
            selectType: ALL,
            onlyContent: false,
            desc: {
                all: '全部',
                positive: '满意',
                negative: '不满意'
            },
            ratings:[]
        }
    },
    created() {
        this.$axios.get('static/data.json').then((res)=>{
            this.ratings = res.data.ratings
            //console.log(res.data.ratings)
        })
        this.$nextTick(()=>{
            this.scroll = new BScroll(this.$refs.ratings,{
                click:true
            })
        })
    },
    methods: {
        /*changeRatingType(type){
            this.$nextTick(()=>{
                console.log(type)
                this.selectType = type
            })
        },*/
        needShow(type,text){
            if(this.onlyContent&&!text){
                return false
            }
            if(this.selectType===ALL){
                return true
            }else{
                return type===this.selectType;
            }
        }
    },
    filters: {
        formatDate(time,pattern="YYYY-MM-DD HH:mm"){
            return moment(time).format(pattern)
        }
    }
}
</script>
<style lang="stylus">
.ratings
    position absolute
    top 174px
    bottom 0
    width 100%
    left 0
    overflow hidden
    .overview
        display flex
        padding 18px 0
        .overview-left
            flex-basis 100px
            width 100px
            border-right 1px solid rgba(7,17,27,0.1)
            text-align center
            @media only screen and (max-width:320px )
                flex-basis 60px
                width 60px
            .score
                font-size 24px
                color rgb(255,153,0)
                line-height 28px
                display inline-block
            .title
                margin 6px 0 8px 0
                font-size 12px
                color rgb(7,17,27)
                line-height 18px
            .rank
                padding-bottom 6px
                font-size 10px
                color rgb(147,153,159)
                line-height 10px
        .overview-right
            flex-grow 1
            padding 0 14px
            .score-wrapper
                margin-bottom 8px
                font-size 0
                .title
                    font-size 12px
                    color rgb(7,17,27)
                    line-height 18px
                    margin-right  12px
                    vertical-align top
                    display inline-block
                .star
                    display inline-block
                    vertical-align top
                .score
                    font-size 12px
                    color rgb(255,153,0)
                    line-height 18px
                    margin-left 12px

            .time
                font-size 0
                .title
                    font-size 12px
                    color rgb(7,17,27)
                    line-height 18px
                    margin-right 12px
                .deltime
                    font-size 12px
                    color rgb(147,153,159)
                    line-height 18px
    .rating-wrapper
        padding 0 18px
        .item
            display flex
            padding 18px 0
            border-bottom 1px solid rgba(7,17,27,0.1)
            .avatar
                flex-basis 28px
                width 28px
                img
                    border-radius 50%
            .content
                flex-grow 1
                position relative
                margin-left 12px
                .name
                    font-size 10px
                    color rgb(7,17,27)
                    line-height 12px
                    margin-bottom 4px
                .star-wrapper
                    margin-bottom 6px
                    font-size 0
                    .star 
                        display inline-block
                        margin-right 6px
                        vertical-align top
                    .delivery
                        display inline-block
                        font-weight 200
                        font-size 10px
                        color rgb(147,153,159)
                        line-height 12px
                .text
                    font-size 12px
                    color rgb(7,17,27)
                    line-height 18px
                    margin-bottom 8px
                .recommend
                    line-height 16px
                    font-size 0
                    .icon-thumb_up
                        font-size 12px
                        color rgb(0,160,220)
                        line-height 16px
                    .recommend-item
                        font-size 9px
                        color rgb(147,153,159)
                        line-height 16px
                        padding 2px 6px
                        margin-left 8px
                        margin-bottom 4px
                        border-radius 1px
                        border 1px solid rgba(7,17,27,0.1)
                        
                .time
                    font-size 10px
                    font-weight 200px
                    position absolute
                    top 0
                    right 0
                    line-height 12px
                    color rgb(147,153,159)
                        
                    


                


</style>

